import request from '@/service'

export const getUserList = params => {
  return request({
    method: 'Get',
    url: 'users',
    params
  })
}

// 获取用户状态
export const updateUserState = params => {
  return request({
    method: 'put',
    url: `users/${params.id}/state/${params.mg_state}`
  })
}

// 添加用户
export const addUser = data => {
  return request({
    method: 'post',
    url: 'users',
    data
  })
}

// 修改用户
export const editUser = id => {
  return request({
    method: 'get',
    url: 'users/' + id
  })
}

// 编辑用户提交
export const editGetUser = data => {
  return request({
    method: 'put',
    url: 'users/' + data.id,
    data
  })
}

// 删除用户
export const delUserInfo = id => {
  return request({
    method: 'delete',
    url: 'users/' + id
  })
}

// 角色列表
export const getRolesList = data => {
  return request({
    method: 'get',
    url: 'roles'
  })
}

// 分配用户角色（权限管理）
export const allotUserPermiss = (id, data) => {
  return request({
    method: 'put',
    url: `users/${id}/role`,
    data: {
      rid: data
    }
  })
}
